package cn.mingyuan.hadoop.fileoperation;

import java.io.*;

public class NcdcData {
	public static String getRandomYear() {
		int year;
		while ((year = (int) (Math.random() * 2000)) > 0) {
			if (year > 1000) {
				return String.valueOf(year);
			}
		}
		return "9999";
	}

	public static String getRandomTemperature() {
		int temperature;
		while ((temperature = (int) (Math.random() * 1000)) > 0) {
			if (temperature > 100) {
				return "-00" + String.valueOf(temperature);
			}
		}
		return "+99991";
	}

	public static void main(String args[]) throws IOException {
		String path = "hdfs://localhost:9000/data/NCDC.txt";
		FileWriter appender = new FileWriter(path);
		String line;
		for (int i = 0; i < 100000; i++) {
			line = "004301199099999" + getRandomYear() + "051518004+68750+023550FM-12+0382" + "99999V0203201N00261220001CN9999999N9" + getRandomTemperature() + "+99999999999\n";
			appender.append(line.getBytes());
		}
		appender.close();
	}
}
